#include"program1.h"
#include"stdio.h"
List::List(int size)
{
	values = new char[size];
	counter = 0;
	maxSize = size - 1;
}

bool List::insert(int index, char x)
{
	int i, a;
	if (index < 0 || index>maxSize + 1)
		return false;
	else
	{
		if (values[index] == NULL || values[index] == '\0')
		{
			values[index] = x;
			return true;
		}
		if (values[index] != NULL)
		{
			for (i = maxSize, a = 0; maxSize <= index; a++, maxSize--)
			{
				values[i - a] = values[i - 1 - a];
			}
			values[index] = x;
			return true;
		}
	}
}

int List::deletechar(char x)
{
	int i, a, b;
	for (i = 0; i <= maxSize; i++)
	{
		if (values[i] == x)
			break;
		else
			continue;
	}
	if (i >= maxSize)
		return 0;
	else
	{
		for (a = maxSize, b = 0; maxSize >= i; b++, maxSize--)
		{
			values[a - b] = values[a - 1 - b];
		}
		if (values[i] != x)
			return i;
	}
}

int List::search(char x)
{
	int i;
	i = 0;
	while (values[i] != x&&i <= maxSize)
	{
		i++;
	}
	if (values[i] == x)
		return i;
	else
		return 0;
}

void List::printList()
{
	int i;
	for (i = 0; i <= maxSize; i++)
	{
		printf("%c ", values[i]);
		if (values[i + 1] == NULL)
			break;
	}
	printf("charaeter count: %d", i);
}